#ifndef BACKEND_H
#define BACKEND_H


#include <QObject>
#include <QQmlEngine>
#include "iap/include/iap.h"

class Backend : public QObject
{
    Q_OBJECT
    QML_ELEMENT
    QML_SINGLETON
    Q_PROPERTY(QString file     READ getFile     WRITE setFile     CONSTANT)
    Q_PROPERTY(QString ioParam1 READ getIoParam1 WRITE setIoParam1 CONSTANT)
    Q_PROPERTY(QString ioParam2 READ getIoParam2 WRITE setIoParam2 CONSTANT)
    Q_PROPERTY(bool    modeSend READ getModeSend WRITE setModeSend CONSTANT)
    Q_PROPERTY(bool    modeRecv READ getModeRecv WRITE setModeRecv CONSTANT)
    Q_PROPERTY(bool    modeUdp  READ getModeUdp  WRITE setModeUdp  CONSTANT)
    Q_PROPERTY(bool    modeUart READ getModeUart WRITE setModeUart CONSTANT)
    Q_PROPERTY(bool    modeCan  READ getModeCan  WRITE setModeCan  CONSTANT)
signals:
    void sig_Md5();
    void sig_Exec();
    void sig_OpenIo();
    void sig_CloseIo();
    void sig_UpdateResultText(QString str);
    void sig_UpdateProcText(QString str);
    void sig_ExecDone();
public slots:
    void slo_Md5();
    void slo_Exec();
    void slo_OpenIo();
    void slo_CloseIo();

public:
    Backend();
    void UpdateToTextArea(QString info);
    QString ToHexString(quint8 * data, qint32 len);

    bool    getModeSend()          {return __modeSend;}
    void    setModeSend(bool val)  {__modeSend = val; }
    bool    getModeRecv()          {return __modeRecv;}
    void    setModeRecv(bool val)  {__modeRecv = val; }
    bool    getModeUdp()           {return __modeUdp; }
    void    setModeUdp(bool val)   {__modeUdp = val;  }
    bool    getModeUart()          {return __modeUart;}
    void    setModeUart(bool val)  {__modeUart = val; }
    bool    getModeCan()           {return __modeCan; }
    void    setModeCan(bool val)   {__modeCan = val;  }
    QString getFile() {return __file;}
    void    setFile(QString file) {__file = file.remove(0, 8);}
    QString getIoParam1() {return __ioParam1;}
    void    setIoParam1(QString param) {__ioParam1 = param;}
    QString getIoParam2() {return __ioParam2;}
    void    setIoParam2(QString param) {__ioParam2 = param;}
private:
    QString __file;
    QString __ioParam1;
    QString __ioParam2;
    bool    __modeSend;
    bool    __modeRecv;
    bool    __modeUdp;
    bool    __modeUart;
    bool    __modeCan;
    Iap     __iap;
};


#endif // BACKEND_H
